package com.nf.handlers;

import com.nf.Constants;
import com.nf.MiniResultSetHandler;
import com.nf.MiniRowProcessor;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * 　　* @description: TODO
 * 　　* @param
 * 　　* @return
 * 　　* @throws
 * 　　* @author Administrator
 * 　　* @date $ $
 *
 */
public class MiniBeanHandler<T> implements MiniResultSetHandler<T> {
    private final Class<? extends T> type;
    private final MiniRowProcessor convert;

    public MiniBeanHandler(Class<? extends T> type){
        this(type, Constants.DEFAULT_ROW_PROCESSOR);
    }

    public MiniBeanHandler(Class<? extends  T> type,MiniRowProcessor convert){
        this.type = type;
        this.convert = convert;
    }

    @Override
    public T handle(ResultSet resultSet) throws SQLException {
        return resultSet.next() ? convert.toBean(resultSet,type) : null;
    }
}
